import sys
import json
from pymongo import MongoClient
import pymongo
from decimal import Decimal
city=sys.argv[1]
db_name=sys.argv[2]
client=MongoClient("182.92.96.120",3719)
db=client['admin']
db.authenticate('root', 'zhuge1116')
db=client[db_name]
borough_info_file="%s/borough_info" % city
def default(obj):
    if isinstance(obj, Decimal):
        return str(obj)
    raise TypeError
newitem={}
with open(borough_info_file, 'w') as f:
    for item in db['borough'].find():
        try:
            newitem['id']= item['borough_id'];
            newitem['borough_shop']= item['borough_config']['borough_shop'];
            newitem['borough_hospital']=item['borough_config']['borough_hospital'];
            newitem['nursery_school']= item['borough_config']['borough_school']['nurser_school'];
            newitem['middle_school']= item['borough_config']['borough_school']['middle_school'];
            newitem['elementary_school']= item['borough_config']['borough_school']['elementary_school'];
            f.write(json.dumps(newitem,default=default))
            f.write("\n")
        except Exception as e:
            print e
            pass

